package com.move;

import org.loon.framework.android.game.action.sprite.Animation;
import org.loon.framework.android.game.action.sprite.Sprite;
import org.loon.framework.android.game.core.geom.Point;
import org.loon.framework.android.game.core.graphics.LImage;

public class Hero 
{
	/*4种主角的状态*/
 public static final int STATIC = 0;
 public static final int LEFT = 1;
 public static final int RIGHT = 2;
 public static final int JUMP = 3;
 
 public static final int JUMP_SPEED = 15;
 public static final int WALK_SPEED = 5;
 
 public Sprite hero;
 private int ScreenWidth;
 private int MapWidth;
 private int vSpeed,hSpeed;
 
 public Hero(int screenwidth,int w)
 {
  this.hero=new Sprite("assets/stand.png");
  this.ScreenWidth=screenwidth;
  this.MapWidth=w;
  vSpeed=JUMP_SPEED;
  hSpeed=WALK_SPEED;
 }
 	
 public void walk_action(int MoveType,int preMove)
 {
  LImage[] walking;
  walking=new LImage[2];
  walking[0]=new LImage("assets/walk2.png");
  walking[1]=new LImage("assets/walk1.png");
  
  LImage stand = new LImage("assets/stand.png");
  
  if(MoveType==RIGHT)
    hero.setAnimation(Animation.getDefaultAnimation(walking, 2, 100));
	  
  else if(MoveType==LEFT)
  {
   walking[0]=walking[0].getMirrorImage();
   walking[1]=walking[1].getMirrorImage();
   hero.setAnimation(Animation.getDefaultAnimation(walking, 2, 100));
  }
  
  else if(MoveType==STATIC)
  {
   if(preMove==RIGHT)
   {
	hero.setRunning(false);	
    hero.getAnimation().addFrame(stand, 100);	   
    hero.setCurrentFrameIndex(2);   
   }  
   else
   {
	hero.setRunning(false);	
	hero.getAnimation().addFrame(stand.getMirrorImage(), 100);	   
	hero.setCurrentFrameIndex(2);   
   }   
  }
	      
 }
 
 public int walk(int MoveType,int x)
 {
  if(MoveType==LEFT)
  {
   if(hero.getX()-5>=ScreenWidth/3)	  
      hero.move_left(hSpeed);
   else if(x+5<=0)
	  x=x+5;
   else if(hero.getX()-5>=0)
	  hero.move_left(hSpeed);
  }
	  
  else if(MoveType==RIGHT)
  {
   if(hero.getX()+5<=2*ScreenWidth/3-hero.getWidth())	  
      hero.move_right(WALK_SPEED); 
   else if(x-5>=-MapWidth+ScreenWidth)
	  x=x-5;
   else if(hero.getX()+5<=ScreenWidth-hero.getWidth())
	  hero.move_right(WALK_SPEED); 
  }
	  
  return x;
 }
 
 
 
 
 public int jump(int MoveType,double suposedY)
 { 
  if(MoveType==JUMP)/*当主角的状态为跳，且速度大于0*/
  {
   hero.move_up(vSpeed);
   vSpeed=vSpeed-1;
   if(vSpeed==0)
     MoveType=-1;  
   }
   else if(MoveType==-1)
   {
	vSpeed++;
	if(hero.getY()+vSpeed<=suposedY)
	   hero.move_down(vSpeed);
	else
	{
	 MoveType=STATIC;
	 vSpeed=JUMP_SPEED;
	}
      
	}
   return MoveType;
  }
 
  
  
 
  
	
}